package o;

import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.huawei.appgallery.assistantdock.buoydock.uikit.remote.RemoteBuoyCallback;
import com.huawei.fastengine.fastview.download.utils.PackageUtils;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.hmf.orb.exception.ConnectRemoteException;
import o.dex.a;
import o.fho.b;

public class bgt {
    private ffa ˏ = null;

    private ffa ˏ(Context context) {
        if (context == null || PackageUtils.HWGAMEBOX_PACKAGE_NAME.equals(context.getPackageName())) {
            return null;
        }
        if (this.ˏ == null) {
            return new ffp(context, PackageUtils.HWGAMEBOX_PACKAGE_NAME);
        }
        return this.ˏ;
    }

    public void ˏ(@NonNull Context context, @NonNull String str, Bundle bundle, @NonNull GameInfo gameInfo) {
        this.ˏ = ˏ(context);
        if (this.ˏ == null) {
            Logger.e("RemoteBuoyWindowManager", "can not create connector for open remote buoy");
            return;
        }
        Logger.ˎ("RemoteBuoyWindowManager", "Enter open, params:" + (bundle == null ? null : bundle.toString()));
        fho.ˋ(this.ˏ, new 3(this, str, bundle, gameInfo, context));
    }

    public void ˋ(@NonNull Context context) {
        this.ˏ = ˏ(context);
        if (this.ˏ == null) {
            Logger.e("RemoteBuoyWindowManager", "can not create connector for close remote buoy");
        } else {
            fho.ˋ(this.ˏ, new b(this) {
                final /* synthetic */ bgt ˊ;

                {
                    this.ˊ = r1;
                }

                public void ˏ(ffd o_ffd, ConnectRemoteException connectRemoteException) {
                    if (connectRemoteException != null) {
                        Logger.ˋ("RemoteBuoyWindowManager", "connect gamebox exception", connectRemoteException);
                        return;
                    }
                    fhz ˋ = o_ffd.ˋ("remotebuoymodule");
                    if (ˋ == null) {
                        Logger.e("RemoteBuoyWindowManager", "Module is null");
                        return;
                    }
                    bgp o_bgp = (bgp) ˋ.ॱ(bgp.class);
                    if (o_bgp == null) {
                        Logger.e("RemoteBuoyWindowManager", "remoteBuoy is null");
                        return;
                    }
                    o_bgp.ˊ();
                    this.ˊ.ˎ();
                }
            });
        }
    }

    public void ˎ() {
        if (this.ˏ != null) {
            this.ˏ.ॱ();
            this.ˏ = null;
        }
    }

    private void ˏ(Context context, RemoteBuoyCallback remoteBuoyCallback) {
        if (context == null || remoteBuoyCallback == null) {
            Logger.e("RemoteBuoyWindowManager", "disposeCallback param is invalid");
            return;
        }
        int ˎ = remoteBuoyCallback.ˎ();
        if (ˎ == 1) {
            fam.ॱ().ˋ(context);
        } else if (ˎ == 0) {
            fam.ॱ().ˎ(context);
            fam.ॱ().ˎ();
        } else if (ˎ == 2) {
            fam.ॱ().ˊ();
        }
    }

    private int ॱ() {
        fae ˏ = fam.ॱ().ˏ();
        if (ˏ != null) {
            bfm requestParams = ˏ.getRequestParams();
            if (requestParams != null) {
                return requestParams.ˊ().ˋ();
            }
        }
        return a.LEFT.ˋ();
    }
}
